package com.haiertvbic.tvnow.service;

import android.content.Context;

import com.haiertvbic.tvnow.baseactivity.SwitchActivity;
import com.haiertvbic.tvnow.protocol.CAEProtocol;
import com.haiertvbic.tvnow.util.Constant;
import com.haiertvbic.tvnow.util.SLog;

public class ServiceUtil {
	/**
	 * dtv下换台
	 * 
	 * @param context
	 * @param cid
	 * @param switchChanellCallback
	 */
	public static void changeChannel(final Context context, final int cid,
			final SwitchChanellCallback switchChanellCallback) {
		VDService.getCurrentSignalSource(new SourceCallback() {

			@Override
			public void returnData(int source) {
				SLog.i("switchchannel", "信号源" + String.valueOf(source));
				SLog.i("switchchannel", "cid==" + String.valueOf(cid));

				// source = 0;
				switch (source) {
				case 0: // DTV 调用DTV换台
					// ============================
					int wcId = VDService.getDTVIdWithWholeCountryId(source,
							(short) cid);
					// wcId = 31;
					SLog.i("switchchannel", "wcId全国表的id是" + wcId);
					if (wcId == 0) {// 代表没读到台号，换台结果为0合理
						switchChanellCallback.returnData(0, SwitchActivity.GET_WHOLE_COUNTRY_ID_FAIL, -1);
					} else {
						SwitchChannel.DTVSwitchChannel(context, wcId,
								switchChanellCallback);
					}
					break;
				case 1: // 机顶盒
					if (CAEProtocol.getCurrentChannel() == cid) {
						switchChanellCallback.returnData(0,
								SwitchActivity.THE_SAME_CID, -1);
						return;
					}
					SwitchChannel.CAESwitchChannel(cid, switchChanellCallback);
					break;
				default:
					switchChanellCallback.returnData(0, SwitchActivity.OTHER_SOURCE,
							-1);
					break;
				}
			}
		});
	}
}
